package com.miao.controller;

import com.miao.entity.EsDocumentEntity;
import com.miao.entity.KnowledgeDocument;
import com.miao.service.TestService;
import com.miao.util.Result;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author <a href="https://gitee.com/a-tom-is-cry">Xing</a>
 * @Date 2025/9/10 22:42
 * @Description
 */
@Slf4j
@Tag(name = "测试服务")
@RestController
@RequestMapping("test")
@CrossOrigin
public class TestControlle {
    @Resource
    private TestService service;

    @GetMapping("RabbitMQ")
    public Result<Object> rabbitMqTest(@Param("msg") String msg){
        service.testSend(msg);
        return new Result<>();
    }

    @GetMapping("delayed")
    public Result<Object> delayedRabbitMQTest(@Param("msg") String msg){
        service.delayedTestSend(msg);
        return new Result<>();
    }

    @PostMapping("add")
    public Result<Object> AddEs(@RequestBody EsDocumentEntity entity){
        service.Save(entity);
        return new Result<>();
    }

    @GetMapping("key")
    public Result<Object> get(@Param("key") String key){
        List<EsDocumentEntity> list = service.list(key);
        return new Result<>().success(list);
    }


    @GetMapping("know")
    @Operation(summary = "获取知识库数据")
    public Result<Object> list(){
        return service.knowList();
    }


    @PostMapping("save")
    @Operation(summary = "向知识库添加数据")
    public Result<Object> save(@RequestBody KnowledgeDocument document){
        return service.save(document);
    }

}
